{%- if storeConfig.smartnews_pixel_config -%}
  {% assign smartnews_pixels = storeConfig.smartnews_pixel_config | strtoarray %}
  {% get_pixels_domain list={smartnews_pixels} pixels_platform=smartnews %}
  {% if list %}
    <!-- SmartNews Ads Pixel Code -->
    <script type='text/javascript'>
      !(function () {
        if (((window.SmartnewsAds = window.SmartnewsAds || {}), !window.SmartnewsAds.p)) {
          var e = (window.SmartnewsAds.p = function () {
            e.callMethod ? e.callMethod.apply(e, arguments) : e.queue.push(arguments);
          });
          (e.push = e), (e.version = '1.0.1'), (e.queue = []);
          var n = document.createElement('script');
          (n.async = !0), (n.src = 'https://cdn.smartnews-ads.com/i/pixel.js');
          var s = document.getElementsByTagName('script')[0];
          s.parentNode.insertBefore(n, s);
        }
      })();
    </script>
    <noscript>
      <img height='1' width='1' style='display:none;' alt='' src='https://i.smartnews-ads.com/p?id=0030a824525cbfa56ced56ce&e=PageView'>
    </noscript>

    <script>
      document.addEventListener('DOMContentLoaded', function() {
        var smartnews_pixels = {{list| json}};
        let smartnews_pixel_id = smartnews_pixels.map(item => item.pixel_id);
        function pushSmartNewsPixel(event){
          smartnews_pixel_id.forEach(id => {
            SmartnewsAds.p(id, event)
          })
        }

        window['TOP_GLOBAL_CALLBACK_LAYER'].register({
          view_content:function(){
            pushSmartNewsPixel("ViewContent")
          },
          search:function(){
            pushSmartNewsPixel("Search")
          },
          purchase:function(){
            pushSmartNewsPixel("Purchase")
          },
          page_view:function(){
            pushSmartNewsPixel("page_view")
          },
          add_to_cart:function(ecdata){
            pushSmartNewsPixel("AddToCart")
          },
          begin_checkout:function(){
            pushSmartNewsPixel("InitiateCheckout")
          },
          sign_up:function(){
            pushSmartNewsPixel("CompleteRegistration")
          }
        })
      });
    </script>
  {% endif %}
{%- endif -%}
